<?php

namespace App\Admin\Controllers;

use App\Models\Free;
use App\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class FreeController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '公益记录';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Free());

        $grid->column('id', __('Id'));
        $grid->model()->orderBy('id','desc');
        $grid->column('user_id', __('用户id'));
        $grid->column('user_name',__('用户昵称'))->display(function () {
            $res = User::find($this->user_id);

            return $res->name;
        });
        $grid->column('one_num', __('本次贡献公益'));
        $grid->column('created_at', __('贡献时间'));

        $grid->actions(function ($actions) {


            // 去掉编辑
            //$actions->disableEdit();

            // 去掉查看
            $actions->disableView();
        });




        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Free::findOrFail($id));



        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Free());

        $form->text('user_id', __('用户id'));
        $form->number('one_num', __('本次贡献'));



        return $form;
    }
}
